<template>
	<view class="myRelease">
		<view class="relase_warp">
			<view
				class="rl_item f f_column"
				v-for="(item,index) in taskList" :key="index"
			>
				<view
					class="f f_align_center" style="padding-bottom: 24rpx;"
					@click="examTask(item)"
				>
					<view class="head_img radius f_shrink0">
						<image :src="item.jobEntity.userHeadUrl" class="autoImg" mode=""></image>
					</view>
					<view class="f f_column f_align">
						<view class="bold re_name mb12 overfont">{{item.jobEntity.title}}</view>
						<view class="f">
							<text>提交时间：{{item.createTime}}</text>
						</view>
					</view>
					<view class="icon_r_tips">
						<i :class="item.auditStatusType  == '10010004' ? 'iconfont iconzu5326 success' : 'iconfont iconzu5326'"></i>
						<text class="t_text">{{$getDict(audit_status_type,item.auditStatusType)}}</text>
					</view>
				</view>
				<view class="relase_btn_b  f f_align f_align_center" v-if="item.auditStatusType  == '10010002'">
					<view class="relase_item_handle" @click="toCallback(item)">拒绝申请</view>
					<view class="relase_item_handle active" @click="examineOk(item)">审核通过</view>
				</view>
			</view>
		</view>
		<!-- 驳回哦 -->
		<toast :visible.sync="visibleToast" :showClose="false">
			<template slot="content">
				<view class="toast_warp">
					<view class="f f_align f_align_center title">
						<view class=""></view>
						<text class="bold">驳回申请</text>
						<i class="iconfont iconlianhe49" @click="visibleToast = false"></i>
					</view>
					<textarea class="areaStyle" v-model="rejectReason" value="" maxlength="100" placeholder="请输入驳回原因" />
					<view class="biding_btn bold" @click="handlerExamine('10010005')">确定驳回</view>
				</view>
			</template>
		</toast>

		<!-- 加载 -->
		<loadMore :isLoading="isLoading" :isDone="isDoneTask" />
	</view>
</template>

<script>
	import loadMore from '@/components/loadMore/loadMore'
	import { mapState } from 'vuex';
	export default {
		data() {
			return {
				visibleToast:false,
				rejectReason:'',
				rowid:'',

				isLoading:false,
				isDoneTask:false,
				jobId:'',
				proId:'',

				page:{
					pageIndex:1,
					pageSize:10,
					totallPage:0
				},
				taskList:[]
			};
		},
		computed:{
			...mapState({
				audit_status_type:state => state.dictArrs.audit_status_type
			})
		},
		onShow() {
			this.init();
		},
		onLoad(option) {
			const _this = this;
			_this.$store.dispatch('getDictlists','audit_status_type');
			if(option.jobId || option.proId){
				_this.jobId = option.jobId || null;
				_this.proId = option.proId || null;
				if(option.jobId){
					_this.activeTabIdx = 1
				}else{
					_this.activeTabIdx = 0
				}
			}
		},
		methods:{
			//查询
			init(){
				if(this.activeTabIdx == 0){
					this.getProjectList();
				}else{
					this.getTaskList();
				}
			},
			//查询项目列表
			async getProjectList(){
				const _this = this;
			},
			//查询审核任务
			async getTaskList(){
				const _this = this;
				_this.isLoading = true;
				_this.isDoneTask = false;
				let res = (await _this.$http('/api/auth/job/listReceiveEntity','POST',{
					page:_this.page.pageIndex,
					limit:_this.page.limit,
					jobId:_this.jobId
				})).data;
				uni.stopPullDownRefresh();
				_this.isLoading = false;
				if(res && res.code == '0'){
					let list = res.data.list;
					_this.page.totalPage = res.data.totalPage;
					if(_this.page.pageIndex <= 1){
						_this.taskList.splice(0);
					}
					if(_this.page.totalPage <= _this.page.pageIndex){
						_this.isDoneTask = true;
					}else{
						_this.isDoneTask = false;
					}
					_this.taskList = _this.taskList.concat(list);
				}else{
					_this.$showToast(res.msg);
				}
			},
			// tab切换
			switchTab (item) {
				this.activeTabIdx = item.index;
				this.page.pageIndex = 1;
				if(this.activeTabIdx == 0){
					this.getProjectList();
				}else{
					this.getTaskList();
				}
			},
			toCallback(item){
				const _this = this;
				_this.rowid = item.id;
				_this.visibleToast = true;
			},
			examineOk(item){
				const _this = this;
				_this.rowid = item.id;
				uni.showActionSheet({
					itemList:['确定要通过当前任务嘛？'],
					success() {
						_this.handlerExamine('10010004');
					}
				})
			},
			//通过驳回操作
			async handlerExamine(type){
				const _this = this;
				let res = (await _this.$http('/api/auth/job/auditReceiveJob','post',{
					auditStatusType:type,
					rejectReason:type == '10010004' ? '' : _this.rejectReason,
					id:_this.rowid
				})).data;
				_this.$showToast(res.msg);
				if(res && res.code == '0'){
					_this.visibleToast = false;
					_this.init();
					_this.rejectReason = '';
				}
			},
			//
			examTask(item){
				this.$navTo('./examTask?jobId='+item.id)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.toast_warp{
		box-sizing: border-box;
		width: 100%;
		position: absolute;
		bottom: 0;left: 0;right: 0;
		background-color: #fff;
		border-radius: 20rpx 20rpx 0 0;
		padding: 24rpx;
		.title{
			padding-bottom: 24rpx;
			font-size: 32rpx;
			.iconfont{
				transform: rotateZ(45deg);
			}
		}
		.areaStyle{
			box-sizing: border-box;
			width: 100%;
			width: 100%;
			height: 200rpx;
			border: solid 1rpx #3F536E;
			border-radius: 8rpx;
			padding: 10rpx;
		}
	}
	.myRelease{
		width: 100%;
		min-height: 100vh;
		border-top: solid 1rpx #F6F6F6;
		background-color: #F6F6F6;
		.relase_warp{
			font-size: 24rpx;
			color: #999999;
			margin:0 24rpx;
			.relase_tip_btn{
				font-size: 22rpx;
				color: $ych_color;
				border: solid 1rpx $ych_color;
				padding: 2rpx 8rpx;
				border-radius: 4rpx;
				margin-left: 8rpx;
			}
			.rl_item{
				padding: 24rpx 24rpx 0;
				background-color: #fff;
				margin-top: 24rpx;
				position: relative;
				border-radius: 12rpx;
				.icon_r_tips{
					position: absolute;
					top:0;right: 0;
					width: 104rpx;
					height: 54rpx;
					@include flex_center;
					.iconfont{
						font-size: 54rpx;
						&.success{
							color: $ych_color;
						}
						&.fail{
							color: #EB4D54;
						}
					}
					.t_text{
						position: absolute;
						font-size: 20rpx;
						color: #fff;
					}
				}
				.head_img{
					width: 90rpx;height: 90rpx;
					margin-right: 26rpx;
					&.radius{
						image{border-radius: 50%;}
					}
					&.project{
						width: 118rpx;height: 118rpx;
						margin-right: 20rpx;
					}
				}
				.re_name{
					font-size: 32rpx;
					color: #1A1A1A;
				}
				.re_margin{
					margin-left: 96rpx;
				}
				.re_price{
					font-size: 32rpx;
					color: #E6212A;
				}
				.relase_btn_b{
					padding: 24rpx 0;
					border-top: solid 1rpx #E6E6E6;
					.relase_item_handle{
						width: 333.333%;
						text-align: center;
						border-left:solid 1rpx #E6E6E6;
						&:first-child{
							border-left: none;
						}
						&.active{
							color: $ych_color;
						}
					}
				}
			}
		}
	}
</style>
